package com.Endurancer.manager.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.Endurancer.common.annotation.Log;
import com.Endurancer.common.core.controller.BaseController;
import com.Endurancer.common.core.domain.AjaxResult;
import com.Endurancer.common.enums.BusinessType;
import com.Endurancer.manager.domain.FriendLinks;
import com.Endurancer.manager.service.IFriendLinksService;
import com.Endurancer.common.utils.poi.ExcelUtil;
import com.Endurancer.common.core.page.TableDataInfo;

/**
 * 链接Controller
 *
 * @author Endurancer
 * @date 2025-02-02
 */
@RestController
@RequestMapping("/manager/links")
public class FriendLinksController extends BaseController
{
    @Autowired
    private IFriendLinksService friendLinksService;

    /**
     * 查询链接列表
     */
//    @PreAuthorize("@ss.hasPermi('manager:links:list')")
    @GetMapping("/list")
    public TableDataInfo list(FriendLinks friendLinks)
    {
        startPage();
        List<FriendLinks> list = friendLinksService.selectFriendLinksList(friendLinks);
        return getDataTable(list);
    }

    /**
     * 导出链接列表
     */
    @PreAuthorize("@ss.hasPermi('manager:links:export')")
    @Log(title = "链接", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FriendLinks friendLinks)
    {
        List<FriendLinks> list = friendLinksService.selectFriendLinksList(friendLinks);
        ExcelUtil<FriendLinks> util = new ExcelUtil<FriendLinks>(FriendLinks.class);
        util.exportExcel(response, list, "链接数据");
    }

    /**
     * 获取链接详细信息
     */
    @PreAuthorize("@ss.hasPermi('manager:links:query')")
    @GetMapping(value = "/{linkId}")
    public AjaxResult getInfo(@PathVariable("linkId") Long linkId)
    {
        return success(friendLinksService.selectFriendLinksByLinkId(linkId));
    }

    /**
     * 新增链接
     */
    @PreAuthorize("@ss.hasPermi('manager:links:add')")
    @Log(title = "链接", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FriendLinks friendLinks)
    {
        return toAjax(friendLinksService.insertFriendLinks(friendLinks));
    }

    /**
     * 修改链接
     */
    @PreAuthorize("@ss.hasPermi('manager:links:edit')")
    @Log(title = "链接", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FriendLinks friendLinks)
    {
        return toAjax(friendLinksService.updateFriendLinks(friendLinks));
    }

    /**
     * 删除链接
     */
    @PreAuthorize("@ss.hasPermi('manager:links:remove')")
    @Log(title = "链接", businessType = BusinessType.DELETE)
	@DeleteMapping("/{linkIds}")
    public AjaxResult remove(@PathVariable Long[] linkIds)
    {
        return toAjax(friendLinksService.deleteFriendLinksByLinkIds(linkIds));
    }
}
